<template>
  <div class="usercenter_wrap">
    <div class="scroll_wrap">
      <div class="head_wrap">
        <div class="left_wrap" @click="editInfo">
          <div class="head_img">
            <img :src="headImg" alt="">
          </div>
          <div class="user_msg">
            <div class="top_wrap">
              <span class="name">{{name}}</span>
              <i class="iconfont icon-edit"></i>
            </div>
            <span class="user_id">UID {{userId}}</span>
          </div>
        </div>
        <router-link tag="span" :to="{path: 'settings'}" class="iconfont icon-shezhi"></router-link>
        <div class="level_wrap">
          <img src="../image/vip.png" alt="">
          <span class="level">{{level}}</span>
        </div>
      </div>
      <div class="accelerate_wrap">
        <div class="list_title">My acceleration</div>
        <ul class="accelerate_list">
          <router-link tag="li" :to="{path: item.link}" class="accelerate_item" v-for="(item, index) in accelerateList" :key="index">
            <span class="balance">{{item.balance}}</span>
            <span class="type">{{item.type}}</span>
          </router-link>
        </ul>
      </div>
      <ul class="nav_list">
        <router-link tag="li" :to="{path: linkArr[index]}" class="nav_item" v-for="(item, index) in navList" :key="index">
          <div class="left_wrap">
            <i class="iconfont" :class="iconList[index]"></i>
            <span class="nav_name">{{item}}</span>
          </div>
          <i class="iconfont icon-fanhui-copy-copy"></i>
        </router-link>
      </ul>
      <div class="logout" @click="logout">Exit logon</div>
    </div>
    <foot></foot>
  </div>
</template>

<script>
export default {
  name: '',
  data () {
    return {
      headImg: '',
      name: '',
      userId: '',
      level: '',
      accelerateList: [
        {
          balance: '',
          type: 'Sharing',
          link: 'speedShare'
        },
        {
          balance: '',
          type: 'Recommended',
          link: 'speedRecommend'
        },
        {
          balance: '',
          type: 'Circulation',
          link: 'speedCirculate'
        }
      ],
      navList: ['Account binding', 'Generalized two-dimensional code', 'Service center', 'Notice'],
      iconList: ['icon-bangding', 'icon-scan', 'icon-serve', 'icon-bulletin'],
      linkArr: ['bindList', 'qrCode', 'serviceCenter', 'notice']
    };
  },
  mounted () {
    setTimeout(() => {
      this.Loading(false);
    }, 600);
    this.getInfo();
  },
  methods: {
    // Editing information
    editInfo () {
      this.$router.push('editInfo');
    },
    // Exit logon
    logout () {
      this.Modal('Exit logon', 'Are you sure you want to withdraw from the account?', ['cancel', 'Sure'], () => {
        this.logOut();
      });
    },
    // Logout interface
    logOut () {
      this.axios.get('index/auth/quit').then(({data}) => {
        if (data.status === 200) {
          this.Toast('Withdraw from success');
          this.$router.push('login');
        } else {
          this.Toast(data.message);
        }
      });
    },
    // Personal center interface
    getInfo () {
      this.axios.get('index/users/userinfo').then(({data}) => {
        if (data.status === 200) {
          this.headImg = data.data.avatar;
          this.name = data.data.nickname;
          this.userId = data.data.account;
          this.level = data.data.level;
          this.accelerateList[0].balance = data.data.share_release;
          this.accelerateList[1].balance = data.data.recommend_release;
          this.accelerateList[2].balance = data.data.accelerate_release;
        } else {
          this.Toast(data.message);
        }
      });
    }
  }
};
</script>

<style lang='scss' scoped>
  @import '../style/mixin.scss';
  .usercenter_wrap {
    background-color: #f5f5f5;
    padding-bottom: 100px;
    height: 100%;
    display: flex;
    flex-direction: column;
    .scroll_wrap{
      flex: 1;
      overflow-y: auto;
      .head_wrap{
        width: 100%;
        padding: 110px 0 40px 30px;
        display: flex;
        justify-content: space-between;
        background-color: $color;
        position: relative;
        margin-bottom: 20px;
        .left_wrap{
          display: flex;
          align-items: center;
          .head_img{
            width: 104px;
            height: 104px;
            border-radius: 50%;
            border: 6px solid #fff;
            margin-right: 20px;
            img{
              width: 92px;
              height: 92px;
              border-radius: 50%;
            }
          }
          .user_msg{
            display: flex;
            flex-direction: column;
            .top_wrap{
              font-size: 32px;
              color: #fff;
              margin-bottom: 20px;
              .name{
                margin-right: 40px;
              }
            }
            .user_id{
              font-size: 24px;
              color: #fff;
            }
          }
        }
        .icon-shezhi{
          position: absolute;
          right: 30px;
          top: 40px;
          font-size: 40px;
          color: #fff;
        }
        .level_wrap{
          height: 58px;
          background-color: #fff;
          border-radius: 30px 0 0 30px;
          display: flex;
          align-items: center;
          font-size: 24px;
          color: #282828;
          padding: 0 16px 0 22px;
          position: absolute;
          bottom: 44px;
          right: 0;
          img{
            width: 30px;
            height: 24px;
            margin-right: 8px;
          }
        }
      }
      .accelerate_wrap{
        width: 100%;
        background-color: #fff;
        margin-bottom: 20px;
        .list_title{
          width: 100%;
          height: 98px;
          line-height: 98px;
          font-size: 26px;
          color: #282828;
          padding-left: 30px;
          border-bottom: 1px solid #e6e6e6;
        }
        .accelerate_list{
          width: 100%;
          padding: 40px 0;
          display: flex;
          border-bottom: 1px solid #e6e6e6;
          .accelerate_item{
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            position: relative;
            .balance{
              font-size: 32px;
              color: #282828;
              margin-bottom: 20px;
            }
            .type{
              font-size: 26px;
              color: #666;
            }
            &::after{
              display: block;
              content: '';
              width: 2px;
              height: 28px;
              background-color: #e6e6e6;
              position: absolute;
              right: 0;
              top: 50%;
              transform: translateY(-50%);
            }
            &:nth-last-child(1)::after{
              display: none;
            }
          }
        }
      }
      .nav_list{
        width: 100%;
        padding: 0 30px;
        background-color: #fff;
        border-bottom: 1px solid #e6e6e6;
        margin-bottom: 40px;
        .nav_item{
          width: 100%;
          height: 108px;
          display: flex;
          justify-content: space-between;
          align-items: center;
          border-bottom: 1px solid #e6e6e6;
          .left_wrap{
            font-size: 28px;
            color: #282828;
            .iconfont{
              font-size: 30px;
              color: $color;
              margin-right: 12px;
            }
          }
          .iconfont{
            font-size: 30px;
            color: #afabbd;
          }
          &:nth-last-child(1){
            border-bottom: none;
          }
        }
      }
      .logout{
        width: 100%;
        height: 96px;
        text-align: center;
        line-height: 96px;
        background-color: #fff;
        font-size: 28px;
        color: #999;
      }
    }
  }
</style>
